package com.eb.service;

import com.eb.dao.GoodsDao;
import com.eb.mapper.GoodsMapper;
import com.eb.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;


import java.util.List;
import java.util.Map;

@Service
public class GoodsServicelmp{

    @Autowired
    private GoodsDao goodsDao;
    @Autowired
    private GoodsMapper goodsMapper;



    public Page<Map<String, Object>> mohu(String goodsName, Integer page, Integer size) {

        return goodsDao.mohu("%"+goodsName+"%",PageRequest.of(page-1,size));
    }

    public void addGoods(Goods goods) {

        goodsMapper.insert(goods);
    }


    public void del(int id) {
        long b = (long)id;
        goodsMapper.deleteByPrimaryKey(b);
    }


    public void updateGoods(Goods goods) {
        goodsMapper.updateByPrimaryKey(goods);
    }


    public Goods findBygoods(int id) {
        long b = (long)id;
        return goodsMapper.selectByPrimaryKey(b);
    }


    public List<Goods> list() {
        return goodsMapper.selectByExample(null);
    }
}
